#!/bin/sh
# @command: ./start-vm.sh hieulq fakevm01 3 64 12
# @output:
# vm-005
# 192.168.0.2
# pub02
# Tue Apr 26 23:18:23 ICT 2011

USER=$1
IMAGE_NAME=$2
CORE=$3
RAM=$4
DURATION=$5

#### Set common environment variables
. ${0%/*}/options.list
####

$ScriptDir/update-conf.sh $USER $CORE $RAM
$ScriptDir/copy-cert.sh $USER

$NimbusClient./bin/cloud-client.sh --run --name $IMAGE_NAME --hours $DURATION > $USER$IMAGE_NAME.tmp

IP=$(sed -n '7,14p' $USER$IMAGE_NAME.tmp | grep IP | cut -d: -f2)
HOST=$(sed -n '7,14p' $USER$IMAGE_NAME.tmp  | grep Hostname | cut -d: -f2)
CREATED_DATE=$(sed -n '7,14p' $USER$IMAGE_NAME.tmp  | grep "Start time" | cut -d: -f2-)
DEFAULT_NAME=$(sed -n '7,14p' $USER$IMAGE_NAME.tmp | grep vm | cut -d'"' -f2) 

echo $DEFAULT_NAME
echo $IP
echo $HOST
echo $CREATED_DATE
